package com.flowerplus.store.common.structure.presenter.user;//package com.quncan.peijue.common.structure.presenter.user;
//
//
//import com.quncan.peijue.api.ApiService;
//import com.quncan.peijue.common.data.http.ApiSubscriber;
//import com.quncan.peijue.common.data.http.HttpCode;
//import com.quncan.peijue.common.data.injector.PerActivity;
//import com.quncan.peijue.common.data.utils.JsonUtil;
//import com.quncan.peijue.models.remote.User;
//import com.quncan.peijue.models.result.ResultBean;
//
//
//import javax.inject.Inject;
//
//import rx.Observable;
//import rx.Subscription;
//import rx.functions.Action1;
//
///**
// * Created by z on.
// * Des:
// * Date: 2017/3/15
// */
//@PerActivity
//public class ChangeUserInfoPresenter implements ChangeUserInfoContract.CountryUtil {
//    private ChangeUserInfoContract.View mView;
//    private ApiService mApiService;
//    private JsonUtil mJsonUtil;
//    private UserDbManager mUserDbManager;
//    private Subscription mSubscribe;
//
//    @Inject
//    public ChangeUserInfoPresenter(ApiService apiService, JsonUtil jsonUtil ) {
//        mApiService = apiService;
//        mJsonUtil = jsonUtil;
//        mUserDbManager = UserDbManager.getInstance();
//    }
//
//    @Override
//    public void onDestroy() {
//        if (mSubscribe != null) mSubscribe.unsubscribe();
//        mView = null;
//    }
//
//    @Override
//    public void onCreate(ChangeUserInfoContract.View view) {
//        mView = view;
//    }
//
//    @Override
//    public void change(final User user) {
//        mSubscribe = mUserDbManager.load().flatMap(new Func1<List<UserDbBean>, Observable<ResultBean<User>>>() {
//            @Override
//            public Observable<ResultBean<User>> call(List<UserDbBean> userDbBeen) {
//                String json = mJsonUtil.toJson(user);
//                return mApiService.changeUserInfo(json, userDbBeen.get(0).getUserId());
//            }
//        }).doOnNext(new Action1<ResultBean<User>>() {
//            @Override
//            public void call(ResultBean<User> userResultBean) {
//                if (userResultBean.getCode().equals(HttpCode.SUCCESS)) {
//                    mUserDbManager.update(user);
//                }
//            }
//        }).subscribe(new ApiSubscriber<ResultBean<User>>(mView) {
//            @Override
//            public void next(ResultBean<User> userResultBean) {
//                mView.complete(userResultBean.getParams());
//            }
//        });
//    }
//}
